// manager.cpp : Defines the entry point for the console application.
//
#include "global.h"
#include "LMContext.h"
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
#include <boost/smart_ptr.hpp>
#include "crypto/sha2.h"
#include "master/LMMaster.h"
#include "worker/LMWorker.h"

#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_EXT "RC2"

static size_t fee_to_pay = 3;
static size_t miner_id = 0;
static size_t thread_num_max = 1;
static boost::asio::ip::tcp::socket* socket_to_server;

int _tmain(int argc, _TCHAR* argv[])
{
	boost::shared_ptr<LMContext> context(new LMContext);

	// Default settings
	context->PoolIp("ypool.net");
	srand(GetTickCount());
	context->PoolPort(8080 + (rand()%8)); // use random port between 8080 and 8087
	SYSTEM_INFO sysinfo;
	GetSystemInfo( &sysinfo );
	context->ThreadNum(sysinfo.dwNumberOfProcessors);  // Right now only support 1 thread
	//commandlineInput.numThreads = sysinfo.dwNumberOfProcessors;
	context->User("shadowzyq.RIC_1");
	context->Password("x");
	std::cout << "V1.7 with " << context->ThreadNum()<< " CPU thread starting..." << std::endl;
	uint32 mbTable[] = {512,256,128,32,8};
	
	// set priority to below normal
	SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
	
	boost::shared_ptr<LMMaster> master(new LMMaster(context));
	master->login();

	// Create workers
	std::vector<boost::shared_ptr<LMWorker>> workers;
	for(int i = 0; i < sysinfo.dwNumberOfProcessors; ++i)
	{
		boost::shared_ptr<LMWorker> worker(new LMWorker(context, master, i));
		worker->start();
		std::cout << "Worker " << i << " started..." << std::endl;
		workers.push_back(worker);
	}


	// run
	master->run();

	return 0;
}

